asm
  ld sp,$43FF
  end asm

#include "./library/smsrnd.bas"
#include "./library/smsdelay.bas"

dim eee as uinteger at $4010
dim seed as uinteger at $4012
dim ee0 as uinteger at $4014
dim ee1 as uinteger at $4016
dim ee2 as uinteger at $4018
dim ee3 as uinteger at $401A
dim ex0 as uinteger at $401C
dim ey0 as uinteger at $401E

seed=0

sub crazyballoonputchar(txp1 as uinteger,typ1 as uinteger,tch1 as ubyte,tat1 as ubyte):
  poke $4800+(typ1 bxor 31)+(txp1*32),tch1
  poke $5000+(typ1 bxor 31)+(txp1*32),tat1
  end sub


for ee0=0 to 31
  for ee1=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    crazyballoonputchar(ee1,ee0,seed band $7F,(ee2 mod 7) bor (ee2 band 8))
    next:next

for ee0=0 to 31
  for ee1=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    crazyballoonputchar(ee1,ee0,$60+(seed mod 8),(ee2 mod 7) bor (ee2 band 8))
    smsdelay(500)
    next:next

for ee0=0 to 15
  for ee1=0 to 15
    crazyballoonputchar(ee1+15,ee0+15,ee0*16+ee1,0)
    smsdelay(500)
    next:next

ex0=8:ey0=8
eee=0
do
  crazyballoonputchar(5,1,48+(int(eee/100) mod 10),0)
  crazyballoonputchar(6,1,48+(int(eee/10) mod 10),0)
  crazyballoonputchar(7,1,48+(eee mod 10),0)

  ee0=in($00) bxor $FF
  crazyballoonputchar(5,3,48+(int(ee0/100) mod 10),0)
  crazyballoonputchar(6,3,48+(int(ee0/10) mod 10),0)
  crazyballoonputchar(7,3,48+(ee0 mod 10),0)

  ee0=in($01) bxor $FF
  crazyballoonputchar(5,4,48+(int(ee0/100) mod 10),0)
  crazyballoonputchar(6,4,48+(int(ee0/10) mod 10),0)
  crazyballoonputchar(7,4,48+(ee0 mod 10),0)

  ey0=ey0-((ee0 band 1)/1)+((ee0 band 2)/2)
  ex0=ex0-((ee0 band 4)/4)+((ee0 band 8)/8)

  ee0=in($02) bxor $FF
  crazyballoonputchar(5,5,48+(int(ee0/100) mod 10),0)
  crazyballoonputchar(6,5,48+(int(ee0/10) mod 10),0)
  crazyballoonputchar(7,5,48+(ee0 mod 10),0)

  ee0=in($03) bxor $FF
  crazyballoonputchar(5,6,48+(int(ee0/100) mod 10),0)
  crazyballoonputchar(6,6,48+(int(ee0/10) mod 10),0)
  crazyballoonputchar(7,6,48+(ee0 mod 10),0)


  crazyballoonputchar(ex0,ey0,eee band 127,0)

  eee=eee+1:smsdelay(2000)
  loop

do:loop

'-------------------------------------------------

do

for eee=$4800 to $4BFF
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(5000)
  next

for eee=$5000 to $53FF
  seed=smsrnd(seed)
  poke eee,seed
  smsdelay(5000)
  next

loop

do:loop



'static ADDRESS_MAP_START( main_map, AS_PROGRAM, 8, crbaloon_state )
'ADDRESS_MAP_GLOBAL_MASK(0x7fff) /* A15 is not decoded */
'AM_RANGE(0x0000, 0x3fff) AM_ROM     /* not fully populated */
'AM_RANGE(0x4000, 0x43ff) AM_MIRROR(0x0400) AM_RAM
'AM_RANGE(0x4800, 0x4bff) AM_MIRROR(0x0400) AM_RAM_WRITE(crbaloon_videoram_w) AM_SHARE("videoram")
'AM_RANGE(0x5000, 0x53ff) AM_MIRROR(0x0400) AM_RAM_WRITE(crbaloon_colorram_w) AM_SHARE("colorram")
'AM_RANGE(0x5800, 0x7fff) AM_NOP
'ADDRESS_MAP_END


'
'
'sub chacknpopputsprite(tlayer as uinteger,txpos as ubyte,typos as ubyte,tid as ubyte,tclut as ubyte):
'  poke $9840+(tlayer*4),typos bxor $FF
'  poke $9841+(tlayer*4),tid
'  poke $9842+(tlayer*4),tclut
'  poke $9843+(tlayer*4),txpos
'  end sub
'
'
''-------------------------------------------------------------------------------
'
'for ee2=0 to 31
'  for ee3=0 to 31
'    chacknpopputchar(ee3,ee2,code("."))
'    next:next
'
'for ee2=0 to 15
'  for ee3=0 to 15
'    chacknpopputchar(ee3+14,ee2+12,ee3+(ee2*16))
'    next:next
'
'for eee=$9800 to $983F '- attr  64 bytes - ?????????????
'  for ee2=1 to 1000:next
'  seed=smsrnd(seed)
'  poke eee,seed
'  next
'
'for eee=$9840 to $98FF '- sprites - 192 bytes
'  poke eee,eee
'  next
'
'ex0=40:ey0=40
'eee=0
'
'do
'  ej0=peek($8809) bxor $FF
'  ej1=peek($880B) bxor $FF
'  chacknpopputchar(8,25,48+(ej0 mod 10))
'  chacknpopputchar(7,25,48+((int(ej0/10)) mod 10))
'  chacknpopputchar(6,25,48+((int(ej0/100)) mod 10))
'  chacknpopputchar(8,26,48+(ej1 mod 10))
'  chacknpopputchar(7,26,48+((int(ej1/10)) mod 10))
'  chacknpopputchar(6,26,48+((int(ej1/100)) mod 10))
'
'  for ee2=0 to 5
'    for ee3=0 to 7
'      chacknpopputsprite(ee3+(ee2*8),ex0+(ee3*16),ey0+(ee2*16),eee band 15,eee band 15)
'      next:next
'
'  ex0=ex0-((ej0 band 1)/1)+((ej0 band 2)/2)
'  ey0=ey0+((ej0 band 4)/4)-((ej0 band 8)/8)
'
'  eee=eee+1
'  for ee2=1 to 500:next
'  loop
'
'do:loop
'
'
